package com.zg.common.core.converter;

import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 将逗号间隔的ID字符串转换成Long列表
 * @author Zxb
 */
@Component
public class IdsConverter implements Converter<String, List<Long>> {

    @Override
    public List<Long> convert(@Nonnull String source) {
        if(StrUtil.isBlank(source)){
            return null;
        }
        return Arrays.stream(source.split(","))
                .map(Long::valueOf)
                .collect(Collectors.toList());
    }

}
